<div class="main">
	<div class="container">
		<div style="background:#fff;min-height: 800px; margin: 20px 0;display: flex;">
			<div class="user_center_left">
				{include file="common/sidenav"}
			</div>
			<div class="user_center_right">
				<div class="user_center_right_hd">
					密码修改
				</div>
				<div class="user_center_right_bd" style="display: flex;align-items: center;justify-content: center;">
					<div class="center_form">
						<form class="layui-form" action="">
							{:token()}
							<div class="layui-form-item">
								<label class="layui-form-label">原密码</label>
								<div class="layui-input-block">
									<input type="password" id="oldpassword" name="oldpassword"  lay-verify="required"
										placeholder="请输入原密码" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">新密码</label>
								<div class="layui-input-block">
									<input type="password" id="newpassword" name="newpassword" lay-verify="required"
										placeholder="请输入新密码" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">确认密码</label>
								<div class="layui-input-block">
									<input type="password" type="number" id="renewpassword" name="renewpassword" lay-verify="required"
										placeholder="请输入确认密码" autocomplete="off" class="layui-input">
								</div>
							</div>
						</form>
						<div class="btn" style="margin-top:30px;">
							<button type="button"
								class="layui-btn layui-btn-lg layui-btn-fluid layui-btn-normal layui-btn-radius"
								onclick="submit()">保存</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var layer;
	layui.use(function() {
		var upload = layui.upload;
		var form = layui.form;
		layer = layui.layer;
		
	});



	function submit() {
		if ($('#oldpassword').val().trim() == '') {
			layer.msg('请输入原密码', {
				icon: 5
			});
			return false;
		}
		if ($('#newpassword').val().trim() == '') {
			layer.msg('请输入新密码', {
				icon: 5
			});
			return false;
		}
		if ($('#renewpassword').val().trim() == '') {
			layer.msg('请输入新密码', {
				icon: 5
			});
			return false;
		}
		if ($('#renewpassword').val().trim() != $('#newpassword').val().trim()) {
			layer.msg('确认密码不一致', {
				icon: 5
			});
			return false;
		}
		$.ajax({
			type: "POST",
			url: "/api.php/user/changepwd",
			dataType: "json",
			data: {
				"oldpassword": $('#oldpassword').val(),
				"newpassword": $('#newpassword').val(),
				"renewpassword": $('#renewpassword').val(),
				"__token__":$('input[name="__token__"]').val().trim(),
			},
			success: function(res) {
				console.log(res);

				if (res.code == 0) {
					layer.msg(res.msg, {
						icon: 5
					});
					$('input[name="__token__"]').val(res.data.token);
				} else {
					layer.msg(res.msg, {
						icon: 6
					}, function() {

						window.location.href = "{:url('index/index')}";
					});
				}
			}
		});

	}
</script>
